package com.qf.controller;

import com.qf.dto.R;
import com.qf.entity.SysRole;
import com.qf.service.RoleService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @Author ztf
 * @Date 16:27 2022/1/10
 **/
@RestController
@RequestMapping("roles")
public class RoleController {
    private RoleService roleService;

    @Autowired
    public void setRoleService(RoleService roleService) {
        this.roleService = roleService;
    }

    @GetMapping("findRoles")
    public R findAllRoles() {
        List<SysRole> roleList = roleService.findAllRoles();
        return R.setOK(roleList);
    }

    @GetMapping("findRoleById")
    public R findRolesById(Long id){
        SysRole role=roleService.findRolesById(id);
        return R.setOK(role);
    }

    @PostMapping("addRole")
    public R addRole(@RequestBody SysRole role) {
        roleService.addRole(role);
        return R.setOK();
    }

    @PostMapping("updateRole")
    public R updateRole(@RequestBody SysRole role) {
        roleService.updateRole(role);
        return R.setOK();
    }

    @DeleteMapping("deleteRoles")
    public R deleteRoles(List<Integer> roleIds) {
        roleService.deleteByIds(roleIds);
        return R.setOK();
    }
}
